import React, { createRef, useReducer } from 'react';
import { Button, Input } from 'antd';

const reducer = (state: any, action: any) => {
  switch (action.type) {
    case 'increment':
      return state + 1;
    case 'decrement':
      return state - 1;
  }
};

const ReduceDemo = () => {
  const [count, dispach] = useReducer(reducer, 0);
  const element = createRef();

  return (
    <div>
      <p>
        当数据或者操作比较多的时候就会使用 useReduce , 下方是 useReduce 的 demo{' '}
      </p>
      <p>count: {count}</p>
      <Button onClick={() => dispach({ type: 'decrement' })}>-1</Button> <br />
      <Button onClick={() => dispach({ type: 'increment' })}>+1</Button> <br />
    </div>
  );
};

export default ReduceDemo;
